package com.mm.domain.user;

import com.baomidou.mybatisplus.annotation.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mm.base.annotation.Sensitive;
import com.mm.base.strategy.SensitiveStrategy;
import com.mm.util.result.DBaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;


/**
 * <p>
 * 用户信息表
 * </p>
 *
 * @author JueDream
 * @since 2021-03-05
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("d_user")
@ApiModel(value="DUser对象", description="用户信息表")
public class DUser extends DBaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "用户编号")
    @TableId(value = "user_id", type = IdType.AUTO)
    public Integer userId;

    @ApiModelProperty(value = "用户名称")
    @TableField("user_name")
    public String userName;

    @ApiModelProperty(value = "用户性别（0-男；1-女 2-其他）")
    @TableField("user_sex")
    public Integer userSex;

    @ApiModelProperty(value = "用户联系方式")
    @Sensitive(strategy = SensitiveStrategy.PHONE)
    @TableField("user_phone")
    public String userPhone;

    @ApiModelProperty(value = "用户登录账户")
    @TableField("user_account")
    public String userAccount;

    @ApiModelProperty(value = "用户登录密码")
    @TableField("user_password")
    //@JsonIgnore
    @Sensitive(strategy = SensitiveStrategy.PASSWORD)
    public String userPassword;

    @ApiModelProperty(value = "用户备注")
    @TableField("user_remark")
    public String userRemark;

    @ApiModelProperty(value = "用户最后登录时间")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JsonFormat(
            pattern = "yyyy-MM-dd HH:mm:ss",
            timezone = "GMT+8"
    )
    @TableField("user_login_time")
    public Date userLoginTime;

    @ApiModelProperty(value = "用户VIP等级ID")
    @TableField("user_level_id")
    public Integer userLevelId;

    /**
     * exist = false 是否为数据库字段
     */
    @ApiModelProperty(value = "用户VIP等级")
    @TableField(exist = false)
    public String userLeveName;

    @ApiModelProperty(value = "用户角色")
    @TableField(exist = false)
    public List<DRole> roles = new ArrayList<>();

    @ApiModelProperty(value = "用户角色ID字符串")
    @TableField(exist = false)
    public String roleIds;

    @ApiModelProperty(value = "用户权限")
    @TableField(exist = false)
    public List<DPermission> permissions = new ArrayList<>();

    public DUser(){}

    @Builder
    public DUser(Integer userId, String userName, Integer userSex, String userPhone, String userAccount, String userPassword, String userRemark, Date userLoginTime, Integer userLevelId, String userLeveName, List<DRole> roles, List<DPermission> permissions) {
        this.userId = userId;
        this.userName = userName;
        this.userSex = userSex;
        this.userPhone = userPhone;
        this.userAccount = userAccount;
        this.userPassword = userPassword;
        this.userRemark = userRemark;
        this.userLoginTime = userLoginTime;
        this.userLevelId = userLevelId;
        this.userLeveName = userLeveName;
        this.roles = roles;
        this.permissions = permissions;
    }
}
